package com.ymatou.iapi.optrade.parameter.model.placeorder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymatou.iapi.optrade.parameter.vo.CatalogApportionVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.SellerPromotionVo;

/**
 */
public class OrderItem {

	// 订单项ID
	private long orderItemId;
	// 订单ID
	private long orderId;
	// 该订单项分摊到的平台优惠券面值
	private BigDecimal ymatouCouponValue = BigDecimal.ZERO;
	// 该订单项分摊到的商家优惠券面值
	private BigDecimal sellerCouponValue = BigDecimal.ZERO;
	// 分摊的商家优惠金额
	private BigDecimal sellerPromotionAmount = BigDecimal.ZERO;
	// 该订单项分摊到的返点金额
	private BigDecimal rebateAmountValue = BigDecimal.ZERO;
	// 享受的商家优惠
	private SellerPromotionVo sellerPromotion;
	
	// 分配到该商品项的规格优惠
	private List<CatalogApportionVo> catalogApportionVos = new ArrayList<CatalogApportionVo>();
	
	// 分摊的商家折扣金额
	private BigDecimal discount = BigDecimal.ZERO;

	private OrderItemVo itemVo;

	public int countPromotionProductNum() {
		int count = 0;
		for (CatalogApportionVo v : catalogApportionVos) {
			count += v.getCount();
		}
		return count;
	}

	/**
	 * 订单项剩余最大可优惠金额
	 *
	 * @return
	 */
	public BigDecimal calcMaxPromotionLeft() {
		BigDecimal result = getItemVo().getProductPrice()
				.multiply(new BigDecimal(getItemVo().getProductNum()))
				.subtract(new BigDecimal("0.01"))
				.subtract(Utils.zeroIfNull(ymatouCouponValue))
				.subtract(Utils.zeroIfNull(sellerCouponValue))
				.subtract(Utils.zeroIfNull(sellerPromotionAmount));
		if (result.compareTo(BigDecimal.ZERO) < 0) {
			return BigDecimal.ZERO;
		}
		return result;

	}

	public long getOrderItemId() {
		return orderItemId;
	}

	public void setOrderItemId(long orderItemId) {
		this.orderItemId = orderItemId;
	}

	public long getOrderId() {
		return orderId;
	}

	public void setOrderId(long orderId) {
		this.orderId = orderId;
	}

	public BigDecimal getYmatouCouponValue() {
		return ymatouCouponValue;
	}

	public void setYmatouCouponValue(BigDecimal ymatouCouponValue) {
		this.ymatouCouponValue = ymatouCouponValue;
	}

	public BigDecimal getSellerCouponValue() {
		return sellerCouponValue;
	}

	public void setSellerCouponValue(BigDecimal sellerCouponValue) {
		this.sellerCouponValue = sellerCouponValue;
	}

	public BigDecimal getSellerPromotionAmount() {
		return sellerPromotionAmount;
	}

	public void setSellerPromotionAmount(BigDecimal sellerPromotionAmount) {
		this.sellerPromotionAmount = sellerPromotionAmount;
	}

	public SellerPromotionVo getSellerPromotion() {
		return sellerPromotion;
	}

	public void setSellerPromotion(SellerPromotionVo sellerPromotion) {
		this.sellerPromotion = sellerPromotion;
	}

	public List<CatalogApportionVo> getCatalogApportionVos() {
		return catalogApportionVos;
	}

	public void setCatalogApportionVos(
			List<CatalogApportionVo> catalogApportionVos) {
		this.catalogApportionVos = catalogApportionVos;
	}

	public OrderItemVo getItemVo() {
		return itemVo;
	}

	public void setItemVo(OrderItemVo itemVo) {
		this.itemVo = itemVo;
	}

	public BigDecimal getDiscount() {
		return discount;
	}

	public void setDiscount(BigDecimal discount) {
		this.discount = discount;
	}

	public BigDecimal getRebateAmountValue() {
		return rebateAmountValue;
	}

	public void setRebateAmountValue(BigDecimal rebateAmountValue) {
		this.rebateAmountValue = rebateAmountValue;
	}
}
